﻿package systems.traer 
{
	
	public class EulerIntegrator implements Integrator
	{
		
		private var s:ParticleSystem;
		
		
		public function EulerIntegrator(_s:ParticleSystem) 
		{
			s = _s;
		}
		public function step(t:Number):void {
			
			s.clearForces();
			s.applyForces();
			
			var i:int;
			var len:int = s.numberOfParticles();
			var p:Particle;
			for (i = 0; i < len; i++) {
				p = s.getParticle(i) as Particle;
				if (p.isFree())
				{
					//p.velocity.addFromValues( p.force.x/(p.mass*t), p.force.y/(p.mass*t), p.force.z/(p.mass*t) );
					p.velocity.x += p.force.x / (p.mass * t);
					p.velocity.y += p.force.y / (p.mass * t);
					p.velocity.z += p.force.z / (p.mass * t);
					//p.position.addFromValues( p.velocity.x/t, p.velocity.y/t, p.velocity.z/t );
					p.position.x += p.velocity.x / t;
					p.position.y += p.velocity.y / t;
					p.position.z += p.velocity.z / t;
				}
			}
			
			
		}
		
	}

}